package com.ricchieri.service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.springframework.transaction.annotation.Transactional;

import com.ricchieri.dao.interf.IDocumentTypeDao;
import com.ricchieri.filter.BasicFilter;
import com.ricchieri.model.DocumentType;
import com.ricchieri.service.interf.IDocumentTypeService;
import com.ricchieri.util.FacesUtil;

@Transactional(readOnly = true)
public class DocumentTypeService implements IDocumentTypeService, Serializable{
	private static final long serialVersionUID = -2704659453561933691L;
	IDocumentTypeDao documentTypeDao;

	public IDocumentTypeDao getDocumentTypeDao() {
		return documentTypeDao;
	}

	public void setDocumentTypeDao(IDocumentTypeDao documentTypeDao) {
		this.documentTypeDao = documentTypeDao;
	}

	@Override
	@Transactional(readOnly = true)
	public List<DocumentType> getAllDocumentsTypes() {
		BasicFilter filter = new BasicFilter();
		return documentTypeDao.getAllDocumentsTypes(filter);
	}

	@Override
	public Map<String, String> getComboDocuments() {
		TreeMap<String, String> documents = new TreeMap<String, String>();
		List<DocumentType> docu = this.getAllDocumentsTypes();
		for (DocumentType documentType : docu) {
			documents.put(FacesUtil.getMessage(documentType.getDescription()), String.valueOf(documentType.getId()));
		}
		return documents;
	}
	
}
